package com.qf.controller;


import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.qf.feign.GoodsFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    EurekaClient eurekaClient;

    //自动注入RestTemplate对象
    @Autowired
    RestTemplate template;

    @Autowired
    LoadBalancerClient balancerClient;

    @RequestMapping("/query")
    public String query(){

        //根据Eureka上注册的服务名称获取实例对象
//        InstanceInfo instanceInfo = eurekaClient.getNextServerFromEureka("QF-GOODS", false);
//        //获取对应模块的url
//        String url = instanceInfo.getHomePageUrl();
        ResponseEntity<String> responseEntity = template.getForEntity("http://qf-goods/query", String.class);

        //返回结果
        return "查询订单" + "&" + responseEntity.getBody();
    }
}
